clear;
clc;
N=100;
Balls=100000;
S=zeros([1 N]);
for i = 1:Balls
    x = 1; %初始化x，x代表小球处于当前层数位置，即某层第x个
    for j = 1:N
        if(rand > 0.5)
        x=x+1; % 0.5的概率小球向右侧掉落
        end
    end
    S(x) = S(x)+1;
end

plot(S);